﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// Filter used to do a gaussian smooth
    /// </summary>
    public class GaussianSmooth : BaseImageFilter
    {
        protected int m_nWidth = 8;
        CConvMatrix sharpMask = new CConvMatrix();

        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianSmooth"/> class.
        /// </summary>
        public GaussianSmooth()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianSmooth"/> class.
        /// </summary>
        /// <param name="_nWidth">Width of the _n.</param>
        public GaussianSmooth(int _nWidth)
        {
            m_nWidth = _nWidth;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GaussianSmooth"/> class.
        /// </summary>
        /// <param name="_guassianSmooth">The _guassian smooth.</param>
        internal GaussianSmooth(GaussianSmooth _guassianSmooth)
        {
        }

        /// <summary>
        /// Gets or sets the width.
        /// </summary>
        /// <value>The width.</value>
        public int Width
        {
            get { return m_nWidth; }
            set { m_nWidth = value; }
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            sharpMask.SetAll(2);
            sharpMask.Pixel = m_nWidth;
            sharpMask.Factor = 16;
            sharpMask.Offset = 0;
            sharpMask.BottomLeft = 1;
            sharpMask.BottomRight = 1;
            sharpMask.TopLeft = 1;
            sharpMask.TopRight = 1;

            new Convolution3x3(sharpMask).Execute(_bitmap);
            return _bitmap;
        }

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new GaussianSmooth(this);
        }
    }
}
